<?php

/*


*/


class tx_danplibs_formlib {
	
		

	/**
	* returns complete HTML for a selectbox
	**/
	 function getSelectBox($name,$items,$multipleCount=1,$default='',$styleinfos='') {
	 	$actualSelect=$default;
	 	if (!is_array($styleinfos)) {
	 		$styleinfos=array();
	 	}
	 	else {
	 		$className=$styleinfos['className']?' class="'.$styleinfos['className'].'" ':'';
	 	}
		if (is_array($actualSelect))
					$actualSelect=array();	//leeren wenn all selectiert ist
		elseif (!is_array($actualSelect))
			$actualSelect=array($actualSelect);
			
		if ($multipleCount==1) {
			$ret='<select name="'.$name.'"'.$className.'>';
		}
		else {
			$ret='<select name="'.$name.'"'.$className.'size="'.$multipleCount.'" multiple="multiple">';
		}
		
		foreach ($items as $k=>$v) {
			if (in_array((string)$k,$actualSelect))
			 $ret.='<option value="'.$k.'" selected="selected">'.$v.'</option>';
			else
			 $ret.='<option value="'.$k.'">'.$v.'</option>';
		}
		$ret .='</select>';
		return $ret;
	}
	
	/**
	* Makes a select to a table and generates an selectbox out of the result:
	
	
	**/
	function getSelectBoxFromDB($field,$table,$pidList,$name,$multipleCount=1,$default,$trimTo=0,$insertEmpty=False,$styleinfos='') {
	
		$items=array();
			
		//standarteintrag
		if ($insertEmpty==TRUE) {			
			$items['0']=' ';
		}			
		$addWhere =$GLOBALS['TSFE']->cObj->enableFields($table);
		//TO-DO Language selects!
		
	
		$fields=$field.',uid';
		$res=$GLOBALS['TYPO3_DB']->exec_SELECTquery($fields,$table,'pid IN ('.$pidList.') '.$addWhere,'',$orderBy,$limit);
		while($row=$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$show=$row[$field];			
			if ($trimTo >0 && strlen($show)>$trimTo) 
				$show=substr($show,0,$trimTo).'...';			
			$items[$row['uid']]=$show;			
		}		
		return tx_danplibs_formlib::getSelectBox($name,$items,$multipleCount,$default,$styleinfos);
	}	
	
			
		
}

php?>